home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Workspace / Locus / Source / SwapView.m < prev    next >
Text File  |  1995-06-12  |  3KB  |  155 lines

  1.  
  2. /*
  3.     Copyright 1993  Jeremy Slade.
  4.  
  5.     You are free to use all or any parts of the Locus project
  6.     however you wish, just give credit where credit is due.
  7.     The author (Jeremy Slade) shall not be held responsible
  8.     for any damages that result out of use or misuse of any
  9.     part of this project.
  10.  
  11. */
  12.  
  13. /*
  14.     Project: Locus
  15.  
  16.     File: SwapView
  17.  
  18.     Description: See SwapView.h
  19.     
  20.     Original Author: Jeremy Slade
  21.  
  22.     Revision History:
  23.         Created
  24.             V.101    JGS    Sat Mar  6 20:27:59 GMT-0700 1993
  25.  
  26. */
  27.  
  28. #import "SwapView.h"
  29.  
  30. #import "Globals.h"
  31.  
  32. #import <objc/List.h>
  33. #import <dpsclient/psops.h>
  34.  
  35.  
  36. @implementation SwapView : View
  37.  
  38.  
  39. // -------------------------------------------------------------------------
  40. //   Creating, Initializing
  41. // -------------------------------------------------------------------------
  42.  
  43.  
  44. + initialize
  45. {
  46.     [self setVersion:SwapView_VERSION];
  47.     return ( self );
  48. }
  49.  
  50.  
  51.  
  52. - initFrame:(const NXRect *)frameRect
  53. {
  54.     [super initFrame:frameRect];
  55.     
  56.     replacementView = [[View allocFromZone:[self zone]] init];
  57.     
  58.     return ( self );
  59. }
  60.  
  61.  
  62.  
  63. - free
  64. {
  65.     // Remove the currentPane if installed
  66.     if ( currentPane ) {
  67.         [self setDelegate:nil];    // So we won't get a new pane when we
  68.         [self swap];            // tell ourselves to swap panes
  69.     }
  70.     
  71.     [replacementView free];
  72.     return ( [super free] );
  73. }
  74.  
  75.     
  76.  
  77. // -------------------------------------------------------------------------
  78. //   SwapView behavior
  79. // -------------------------------------------------------------------------
  80.  
  81.  
  82. - setDelegate:anObject
  83. {
  84.     delegate = anObject;
  85.     return ( self );
  86. }
  87.  
  88.  
  89.  
  90. - delegate
  91. {
  92.     return ( delegate );
  93. }
  94.  
  95.  
  96.  
  97. - swap:sender
  98. {
  99.     [self swap];
  100.     return ( self );
  101. }
  102.  
  103.  
  104.  
  105. - swap
  106. {
  107.     id    installedView;
  108.     
  109.     // Un-install currentPane if installed
  110.     if ( currentPane ) {
  111.         installedView = [subviews objectAt:0];
  112.         [installedView removeFromSuperview]; // Remove it from our view list
  113.         [currentPane setContentView:installedView]; // Put it back in its window
  114.         currentPane = nil;
  115.     }
  116.     
  117.     // Ask the delegate for the new pane
  118.     if ( [delegate respondsTo:@selector(swapPaneFor:)] )
  119.         currentPane = [delegate swapPaneFor:self];
  120.         
  121.     // Install the new pane as a subview our subivew:
  122.     if ( currentPane ) {
  123.         // Get the currentPane's contentView -- setting the replacementView as its  
  124.         // new contentView will return the old contentView
  125.         installedView = [currentPane setContentView:replacementView];
  126.         
  127.         // Install the new view as our subview
  128.         [self addSubview:installedView];
  129.         [self display];
  130.     }
  131.     
  132.     return ( self );
  133. }
  134.  
  135.  
  136.  
  137. - drawSelf:(const NXRect *)rects :(int)rectCount
  138. /*
  139.     Fill ourselves with the window's background color/gray
  140. */
  141. {
  142.     //if ( [self shouldDrawColor] )
  143.     //    PSsetcolor ( ... );
  144.     //else
  145.         PSsetgray ( [window backgroundGray] );
  146.     NXRectFill ( &bounds );
  147.     return ( self );
  148. }
  149.  
  150.  
  151.  
  152. @end
  153.  
  154.  
  155.